package cn.edu.imau.zy.examination.service.impl;

import java.util.List;

import cn.edu.imau.zy.common.utils.DateUtils;
import cn.edu.imau.zy.examination.aspect.Examination;
import cn.edu.imau.zy.examination.domain.*;
//import cn.edu.imau.zy.examination.dto.ElExamVO;
import cn.edu.imau.zy.examination.mapper.ElExamMapper;
import cn.edu.imau.zy.examination.service.IElExamDepartService;
import cn.edu.imau.zy.examination.service.IElExamRepoService;
import cn.edu.imau.zy.examination.service.IElExamService;
import cn.edu.imau.zy.examination.service.IElPaperService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.transaction.annotation.Transactional;

/**
 * 课程Service业务层处理
 * 
 * @author xsc
 * @date 2021-07-28
 */
@Service
public class ElExamServiceImpl extends ServiceImpl<ElExamMapper, ElExam> implements IElExamService
{
    @Autowired
    private IElExamRepoService elExamRepoService;

    @Autowired
    private IElPaperService elPaperService;

    @Autowired
    private IElExamDepartService elExamDepartService;

    @Override
    public List<ElExam> queryList(ElExam elExam) {
        LambdaQueryWrapper<ElExam> lqw = Wrappers.lambdaQuery();
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            return this.list(lqw);
    }

    @Override
    @Transactional
    public boolean elSave(ElExam elExam) {
        ElPaper elPaper = new ElPaper();
        boolean save = this.save(elExam);

        QueryWrapper<ElPaper> wrapper = new QueryWrapper<>();
        wrapper.eq("id",elExam.getPaperId());

        elPaper.setTotalTime(elExam.getTotalTime());
        elPaper.setQualifyScore(elExam.getQualifyScore());
        elPaper.setLimitTime(elExam.getEndTime());
        elPaper.setExamId(elExam.getId());
        elPaperService.update(elPaper,wrapper);

        elExam.getDepaId().forEach(item->{
            ElExamDepart elExamDepart = new ElExamDepart();
            elExamDepart.setDepartId(item);
            elExamDepart.setExamId(elExam.getId());
            elExamDepartService.save(elExamDepart);
        });

        System.out.println(elExam);
        return save;
    }
}
